<template>
    <div class="ivu-mb-8" v-font="14">
		<ButtonGroup>
		<Button custom-icon="iconfont icon-Word" :type="type" :disabled="butDisabled"
		 @click="handleCase" ghost>
    	<slot></slot>
		</Button>
		<Button icon="ios-eye" @click="handlePreview" :type="type" 
		ghost :disabled="butDisabled" v-show="previewShow"></Button>
		</ButtonGroup>
	</div>
</template>
<script>
export default {
	name: 'DocButton',
	data(){
		return{
			butDisabled:false,
			type:'primary',
			previewShow:false
		}
	},
	props: {
		to: {
		  type: String
		},
		caseInfo:{
			type: Object,
			default: {}
		}
	},
	computed:{
	},
	watch:{
		caseInfo(newValue,oldValue){
			//设置颜色文档是否存在
			if(newValue.docs==null){
				this.type='primary'
				this.previewShow=false
			}else{
				let n=newValue.docs.split(",")
				if(n.includes(this.to)){
					this.type="warning"
					this.previewShow=true
				}else{
					this.type="primary"
					this.previewShow=false
				}
			}
			//设置是否编辑
			if(this.caseInfo.step_code==0){
				if(parseInt(this.to.substring(3))>150){
					this.butDisabled=true
				}else{
					this.butDisabled=false
				}
			} else if(this.caseInfo.step_code==1){
				if(parseInt(this.to.substring(3))>200){
					this.butDisabled=true
				}else{
					this.butDisabled=false
				}
			}else if(this.caseInfo.step_code==2){
				if(parseInt(this.to.substring(3))>300){
					this.butDisabled=true
				}else{
					this.butDisabled=false
				}
			}else if(this.caseInfo.step_code==3){
				if(parseInt(this.to.substring(3))>400){
					this.butDisabled=true
				}else{
					this.butDisabled=false
				}
			}else{
				this.butDisabled=false
			}
		}
	},
	methods:{
		handleCase(){
			this.$router.push({name:this.to,query:{case_no:this.caseInfo.case_no,party_type:this.caseInfo.party_type}})
			//let {href}=this.$router.resolve({name:this.to,query:{case_no:this.caseInfo.case_no,party_type:this.caseInfo.party_type}})
			//window.open(href,"_blank")
		},
		handlePreview(){
			let routeUrl = this.$router.resolve({
			    path: "/Preview",
			    query: {to:this.to,case_no:this.caseInfo.case_no,case_year:this.caseInfo.case_year}
			})
			window.open(routeUrl.href, '_blank')
		}
	},
	mounted(){}
}
</script>